<template>
    <div>
        <h1>病房信息新增</h1>
        <table class="table">
            <tbody>
                <tr>
                    <td>病房名称</td>
                    <td><input type="text" v-model="data.BingName"></td>
                </tr>
                <tr>
                    <td>房间号</td>
                    <td><input type="text" v-model="data.BingNum"></td>
                </tr>
                <tr>
                    <td>所属科室</td>
                    <td>
                        <select v-model="data.DepId">
                            <option value="0">请选择</option>
                            <option v-for="a in bang" :value="a.DepId">{{a.DepName}}</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>床位总数量</td>
                    <td><input type="text" v-model="data.BingSum"></td>
                </tr>
                <tr>
                    <td>床位状态</td>
                    <td><input type="checkbox" v-model="data.BingBedState">选中为已满没选中为未满</td>
                </tr>
                <tr>
                    <td>空闲床数量</td>
                    <td><input type="text" v-model="data.BingBedNum"></td>
                </tr>

                <tr>
                    <td>创建时间</td>
                    <td><input type="date" v-model="data.BingDate"></td>
                </tr>
                <tr>
                    <td>病房状态</td>
                    <td><input type="checkbox" v-model="data.BingState">选中为启用，未选中为维修</td>
                </tr>
                <tr>
                    <td></td>
                    <td><input type="button" value="新增" @click="Add"></td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">


import { ref ,onMounted} from 'vue';
import axios from 'axios';
import { useRouter } from 'vue-router';
onMounted(()=>{
    xia()
})

//下拉框
const bang = ref([{
    "DepId": 1,
    "DepName": "脑科",
    "DepNum": "120",
    "DepMiao": "术业有专攻，全是教授",
    "DepDate": "2025-05-01T00:00:00",
    "DepIsDelete": true
}])
const xia = ()=>{
    axios.get('https://localhost:7087/api/Bing/Xia').then(res=>{
        bang.value = res.data;
    })
}

const data = ref({
    "BingId": 0,
  "BingName": "",
  "BingNum": 0,
  "DepId": 0,
  "BingSum": 0,
  "BingBedState": false,
  "BingBedNum": 0,
  "BingDate": "",
  "BingState": true
})
const router = useRouter()
const Add =()=>{
    if(data.value.BingName==""){
        alert('病房名称不能为空')
        return
    }
    axios.post('https://localhost:7087/api/Bing/BingAdd',data.value).then(res=>{
        if(res.data>0){
            alert('新增成功');
            router.push({path:"/BingShow"});
        }
        else{
            alert('新增失败');
        }
    })
}

</script>

<style scoped>

</style>